<%@ page language="java" import="java.util.*,com.safewind.model.User"
	pageEncoding="UTF-8"%>
<script type="text/javascript">
	function b_click(m) {
		var st = document.getElementsByClassName("bal");
		var divst = document.getElementsByClassName("bal_sub_content");
		for (var k = 0; k < st.length; k++) {
			if (k != m) {
				divst[k].style.display = "none";
			} else {
				divst[k].style.display = "block";
			}
		}
	}
</script>
<div class="balances content" style="display:none">
	<div class="subnav">
		<div class="nav_content">
			<ul>
				<li class="bal"><a id="user_info" href="javascript:void(0);"
					onclick="b_click(0);userInfoClick();">账户信息</a></li>
				<li class="bal"><a href="javascript:void(0);"
					onclick="b_click(1);getBalances();">余额详情</a></li>
				<li class="bal"><a href="javascript:void(0);"
					onclick="b_click(2);getRestBal();">充值提现</a></li>
			</ul>
		</div>
	</div>
	<div class="sub_content bal_sub_content">
		<div class="edit_password">修改密码</div>

		<div class="bal_user_info">
			<form>
				<table>
					<tr>
						<td class="left_td">姓&nbsp;&nbsp;&nbsp;名：</td>
						<td><label><%=((User) session.getAttribute("user")).getUserName()%></label></td>
					</tr>
					<tr>
						<td class="left_td">原密码：</td>
						<td><input id="oldpassword" type="password"
							name="oldpassword" size="20" /></td>
						<td><div id="wrongPassword"
								style="display:none;font-size:14px;">密码错误</div></td>
					</tr>
					<tr>
						<td class="left_td">新密码：</td>
						<td><input id="newpassword" type="password"
							name="newpassword" size="20" /></td>
					</tr>
					<tr>
						<td class="left_td">确认密码：</td>
						<td><input id="rnewpassword" type="password"
							name="rnewpassword" size="20" /></td>
					</tr>
					<tr>
						<td class="left_td"><input
							style="width: 60px;font-size:16px;" type="button" value="确定"
							name="Submit" onclick="editPassword()"></td>
						<td style="text-align:center;"><input id="resetInfo"
							style="width: 60px;font-size:16px;" type="reset" value="重填"
							name="Submit2"></td>
					</tr>
				</table>
			</form>
		</div>
		<script type="text/javascript">
			function userInfoClick() {
				document.getElementById('resetInfo').click();
				document.getElementById('wrongPassword').style.display = 'none';
			}
			function editPassword() {
				var oldpassword = document.getElementById('oldpassword');
				var newpassword = document.getElementById('newpassword');
				var rnewpassword = document.getElementById('rnewpassword');
				if (oldpassword.value == "") {
					alert("原密码不能为空！");
					oldpassword.focus();
					return false;
				}
				if (newpassword.value == "") {
					alert("新密码不能为空！");
					newpassword.focus();
					return false;
				}
				if (rnewpassword.value == ""
						|| newpassword.value != rnewpassword.value) {
					alert("前后两次输入的密码不一致！");
					rnewpassword.focus();
					return false;
				}
				$
						.ajax({
							type : "POST",
							url : "${pageContext.request.contextPath}/user/editPassword",
							datatype : "json",
							data : {
								"password" : oldpassword.value,
								"newpassword" : newpassword.value
							},
							success : function(data) {
								if (data.success) {
									alert("修改成功");
									document.getElementById('user_info')
											.click();
								} else {
									document.getElementById('wrongPassword').style.display = 'block';
								}
							},
							error : function() {
								alert("网络异常");
								window.location.href = '${pageContext.request.contextPath}/redirect/login';
								return;
							}
						});

			}
		</script>
	</div>
	<div class="sub_content bal_sub_content" style="display:none">
		<div class="p_history">
			<ul id="send_bal_li">
			</ul>
		</div>
		<script type="text/javascript">
			function getBalances() {
				$
						.ajax({
							type : "POST",
							url : "${pageContext.request.contextPath}/value/getAll",
							datatype : "json",
							success : function(data) {
								if (data.success) {
									var html = '';
									var list = data.list;
									for (var i = 0; i < list.length; i++) {
										html += '<li>'
												+ formatDate(list[i].addTime)
												+ ' ' + list[i].operate + ' '
												+ list[i].cost + '</li>';
									}
									document.getElementById('send_bal_li').innerHTML = html;
								} else {
									alert('操作异常');
								}
							},
							error : function() {
								alert('操作异常');
								window.location.href = '${pageContext.request.contextPath}/redirect/login';
								return;
							}
						});
			}
		</script>
	</div>
	<div class="sub_content bal_sub_content" style="display:none">
		<div class="rest_bal">
			<p id="rest"></p><br/><br/><br/>
			<p>如果需要充值或者提现，请联系管理员，谢谢。</p>
			<p>联系方式：微信<label id="wx"></label>；电话号码：<label id="phone"></label></p>
		</div>
		<script type="text/javascript">
			function getRestBal() {
				$
						.ajax({
							type : "POST",
							url : "${pageContext.request.contextPath}/user/getValue",
							datatype : "json",
							success : function(data) {
								if (data.success) {
									document.getElementById('rest').innerHTML = data.value;
									document.getElementById('wx').innerHTML = data.wx;
									document.getElementById('phone').innerHTML = data.phone;
								} else {
									alert('操作异常');
								}
							},
							error : function() {
								alert('操作异常');
								window.location.href = '${pageContext.request.contextPath}/redirect/login';
								return;
							}
						});
			}
		</script>
	</div>
	<div class="clear"></div>
</div>
